home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fspdev / fspdev.h < prev    next >
C/C++ Source or Header  |  1991-06-26  |  9KB  |  212 lines

  1. /*
  2.  * fspdev.h --
  3.  *
  4.  *    Declarations for pseudo-devices and pseudo-filesystems.
  5.  *
  6.  *    A pseudo-device is a file that acts as a communication channel
  7.  *    between a user-level server process (hereafter called the "server"),
  8.  *    and one or more client processes (hereafter called the "clients").
  9.  *    Regular filesystem system calls (Fs_Read, Fs_Write, Fs_IOControl,
  10.  *    Fs_Close) by a client process are forwarded to the server using
  11.  *    a request-response procotol.  The server process can implement any
  12.  *    sort of sementics for the file operations it wants to. The general
  13.  *    format of Fs_IOControl, in particular, lets the server implement
  14.  *    any remote procedure call it cares to define.
  15.  *
  16.  *    A pseudo-filesystem is a whole sub-tree of the filesystem that
  17.  *    is controlled by a user-level server process.  The basic request
  18.  *    response protocol is still used for communication.  In addition to
  19.  *    file access operations, file naming operations are handled by
  20.  *    a pseudo-filesystem server.  The pseudo-filesystem server can
  21.  *    establish pseudo-device like connections for each pseudo-file
  22.  *    that is opened, or it can open regular files and connect its
  23.  *    clients to those files instead.
  24.  *
  25.  *    The user include file <dev/pdev.h> defines the request-response
  26.  *    protocol as viewed by the user-level server process.
  27.  *
  28.  * Copyright 1987 Regents of the University of California
  29.  * All rights reserved.
  30.  *
  31.  *
  32.  * $Header: /sprite/src/kernel/fspdev/RCS/fspdev.h,v 9.3 91/06/26 01:06:21 mottsmth Exp $ SPRITE (Berkeley)
  33.  */
  34.  
  35. #ifndef _FSPDEVX
  36. #define _FSPDEVX
  37.  
  38. #include <fs.h>
  39. #include <proc.h>
  40. #include <fsprefix.h>
  41. #include <fsrmt.h>
  42. #include <dev/pdev.h>
  43. /*
  44.  * Fspdev_State is returned from the SrvOpen routine to the CltOpen routine.
  45.  * It is also sent via RPC from the remoteCltOpen routine to the localCltOpen
  46.  * routine.  In this second case, the processID and uid of the remote client
  47.  * is initialized.
  48.  */
  49. typedef struct Fspdev_State {
  50.     Fs_FileID    ctrlFileID;    /* Control stream FileID */
  51.     /*
  52.      * The following fields are used when the client process is remote
  53.      * from the server host.
  54.      */
  55.     Proc_PID    procID;        /* Process ID of remote client */
  56.     int        uid;        /* User ID of remote client */
  57.     Fs_FileID    streamID;    /* Client's stream ID used to set up a
  58.                  * matching stream here on the server */
  59. } Fspdev_State;
  60.  
  61. /*
  62.  * Both the pseudo-device and pseudo-filesystem implementation use a
  63.  * control stream to note what host runs the master, and to keep a seed.
  64.  * With pseudo-devices the control IO handle is hooked to a stream that
  65.  * is returned to the server, and the server reads new streamIDs off
  66.  * of this stream.  With pseudo-filesystems the server gets new streamIDs
  67.  * via IOC_PFS_OPEN, instead, and the control stream is used to keep
  68.  * a pointer to the prefix table entry that represents the pseudo-filesystem.
  69.  *
  70.  * There is a control handle kept on both on the file server and on the
  71.  * host running the server process.  The one on the file server is used
  72.  * by the SrvOpen routine to detect if a master exists, and the one on
  73.  * the server's host is used for control messages, and it also is used
  74.  * to detect if the server process is still alive (by looking at serverID).
  75.  */
  76. typedef struct Fspdev_ControlIOHandle {
  77.     Fsrmt_IOHandle rmt;    /* FSIO_CONTROL_STREAM or FSIO_PFS_CONTROL_STREAM.
  78.                  * This is a remote I/O handle in order to do
  79.                  * a remote close to the name server so
  80.                  * the serverID field gets cleaned up right. */
  81.     int serverID;        /* Host ID of server process.  If NIL it
  82.                  * means there is no server.  This is kept */
  83.     int    seed;            /* Used to make FileIDs for client handles */
  84.     /*
  85.      * These fields are used to implement reading from a pdev control stream.
  86.      */
  87.     List_Links    queueHdr;    /* Control message queue, pdev's only */
  88.     List_Links readWaitList;    /* So the server can wait for control msgs */
  89.     Fsio_LockState lock;        /* So the server can flock() the pdev file */
  90.     /*
  91.      * Cached I/O attributes.
  92.      */
  93.     int        accessTime;    /* Time of last write operation */
  94.     int        modifyTime;    /* Time of last read operation */
  95.     /*
  96.      *  IOC_SET/GET_OWNER support.
  97.      */
  98.     Ioc_Owner    owner;        /* Owning process or family */
  99.     /*
  100.      * This pointer is used to clean up the prefix table entry that the
  101.      * naming request-response stream is hooked to (pseudo-filesystems)
  102.      */
  103.     Fsprefix *prefixPtr;    /* Prefix of pseudo-filesystem */
  104. } Fspdev_ControlIOHandle;
  105.  
  106. /*
  107.  * Circular buffers are used for a request buffer and a read data buffer.
  108.  * These buffers are in the address space of the server process so the
  109.  * server can access them without system calls.  The server uses I/O controls
  110.  * to change the pointers.
  111.  */
  112. typedef struct Fspdev_CircBuffer {
  113.     Address data;        /* Location of the buffer in user-space */
  114.     int firstByte;        /* Byte index of first valid data in buffer.
  115.                  * if -1 then the buffer is empty */
  116.     int lastByte;        /* Byte index of last valid data in buffer. */
  117.     int size;            /* Number of bytes in the circular buffer */
  118. } Fspdev_CircBuffer;
  119.  
  120. /*
  121.  * Fspdev_ServerIOHandle has the main state for a client-server connection.
  122.  * The client's handle is a stub which just has a pointer to this handle.
  123.  */
  124. typedef struct Fspdev_ServerIOHandle {
  125.     Fs_HandleHeader hdr;        /* Standard header, type FSIO_LCL_PSEUDO_STREAM */
  126.     Sync_Lock lock;        /* Used to synchronize access to this struct. */
  127.     int flags;            /* Flags bits are defined in fsPdev.c */
  128.     int selectBits;        /* Select state of the pseudo-stream */
  129.     Proc_PID serverPID;        /* Server's processID needed for copy out */
  130.     Proc_PID clientPID;        /* Client's processID needed for copy out */
  131.     Fspdev_CircBuffer    requestBuf;    /* Reference to server's request buffer.
  132.                  * The kernel fills this buffer and the
  133.                  * server takes the requests and data out */
  134.     Address nextRequestBuffer;    /* The address of the next request buffer in
  135.                  * the server's address space to use.  We let
  136.                  * the server change buffers in mid-flight. */
  137.     int nextRequestBufSize;    /* Size of the new request buffer */
  138.     Fspdev_CircBuffer readBuf;        /* This buffer contains read-ahead data for
  139.                  * the pseudo-device.  The server process puts
  140.                  * data here and the kernel removes it to
  141.                  * satisfy client reads. If non-existent,
  142.                  * the kernel asks the server explicitly for
  143.                  * read data with PDEV_READ requests */
  144.     Pdev_Op operation;        /* Current operation.  Checked when handling
  145.                  * the reply. */
  146.     Pdev_Reply reply;        /* Server's reply message */
  147.     Address replyBuf;        /* Pointer to reply data buffer.  This is in
  148.                  * the client's address space if the
  149.                  * FS_USER flag is set */
  150.     int replySize;        /* Amount of data the client expects returned */
  151.     Sync_Condition setup;    /* This is notified after the server has set
  152.                  * up buffer space for us.  A pseudo stream
  153.                  * can't be used until this is done. */
  154.     Sync_Condition access;    /* Notified after a RequestResponse to indicate
  155.                  * that another client process can use the
  156.                  * pseudo-stream. */
  157.     Sync_Condition caughtUp;    /* This is notified after the server has read
  158.                  * or set the buffer pointers.  The kernel
  159.                  * waits for the server to catch up
  160.                  * before safely resetting the pointers to
  161.                  * the beginning of the buffer */
  162.     Sync_Condition replyReady;    /* Notified after the server has replied */
  163.     List_Links srvReadWaitList;    /* To remember the server process waiting
  164.                  * to read new pointer values. */
  165.     Sync_RemoteWaiter clientWait;/* Client process info for I/O waiting */
  166.     List_Links cltReadWaitList;    /* These lists are used to remember clients */
  167.     List_Links cltWriteWaitList;/*   waiting to read, write, or detect */
  168.     List_Links cltExceptWaitList;/*   exceptions on the pseudo-stream. */
  169.     Fspdev_ControlIOHandle *ctrlHandlePtr;    /* Back pointer to control stream */
  170.     /*
  171.      * The following fields support pseudo-filesystems.
  172.      */
  173.     Fs_FileID    userLevelID;    /* User-defined FileID for connections to
  174.                  * pseudo-filesystem servers.  This is passed
  175.                  * as 'prefixID' of name operation arguments
  176.                  * to represent lookup starting points. */
  177.     struct {            /* Info needed to set up new pdev connection */
  178.     int clientID;        /* Host ID of client doing PFS_OPEN */
  179.     int useFlags;        /* Usage flags of the open */
  180.     char *name;        /* Name of pseudo-file, for handle headers */
  181.     } open;
  182. } Fspdev_ServerIOHandle;
  183.  
  184. /*
  185.  * The client side stream for a pseudo-device.  This keeps a reference
  186.  * to the server's handle with all the state.
  187.  */
  188. typedef struct Fspdev_ClientIOHandle {
  189.     Fs_HandleHeader    hdr;
  190.     Fspdev_ServerIOHandle    *pdevHandlePtr;
  191.     List_Links        clientList;
  192.     struct Vm_Segment    *segPtr;    /* Reference to code segment needed
  193.                      * to flush VM cache. JMS */
  194. } Fspdev_ClientIOHandle;
  195.  
  196. extern Boolean fspdev_Debug;
  197.  
  198. extern void Fspdev_Bin _ARGS_((void));
  199. extern ReturnStatus FspdevPfsDomainInfo _ARGS_((Fs_FileID *fileIDPtr, 
  200.             Fs_DomainInfo *domainInfoPtr));
  201. extern void Fspdev_InitializeOps _ARGS_((void));
  202.  
  203. extern void Fspdev_PrintTrace _ARGS_((ClientData numRecs));
  204.  
  205. extern ReturnStatus Fspdev_PrintRec _ARGS_((ClientData clientData, int event,
  206.             Boolean printHeaderFlag));
  207.  
  208. extern ReturnStatus Fspdev_TraceInit _ARGS_((void));
  209.  
  210.  
  211. #endif _FSPDEVX
  212.